<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
                xmlns:h="http://xmlns.jcp.org/jsf/html"
                xmlns:f="http://xmlns.jcp.org/jsf/core"
                xmlns:p="http://primefaces.org/ui"
                template="/WEB-INF/template.xhtml">

    <ui:define name="title">
        DataList <span class="subitem">Lazy</span>
    </ui:define>

    <ui:define name="description">
        DataList has built-in support to deal with huge datasets. In order to enable lazy loading, a LazyDataModel needs to be implemented
        to query the datasource when pagination happens. This example uses an in-memory list to mimic a real datasource like a database.
        <p>
            <strong>In a real application, loading should be executed with the query built using the information passed to the load method.</strong>
        </p>
    </ui:define>

    <ui:param name="documentationLink" value="/components/datalist"/>
    <ui:param name="widgetLink" value="DataList"/>

    <ui:define name="implementation">
        <div class="card">
            <h:form id="form">
                <p:dataList value="#{dtLazyView.lazyModel}" var="customer" type="unordered" itemType="none"
                            paginator="true" rows="5" rowsPerPageTemplate="5,10,20" pageLinks="5"
                            paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}">
                    <h:panelGrid columns="2" style="width:100%" cellspacing="20">

                        <p:outputPanel>
                            <h:panelGrid columns="2" cellpadding="5">

                                <h:outputText value="Name:"/>
                                <h:outputText value="#{customer.name}"/>

                                <h:outputText value="Country"/>
                                <p:column>
                                    <span class="flag flag-#{customer.country.code}" style="width: 30px; height: 20px"/>
                                    <h:outputText style="vertical-align: middle; margin-left: .5rem"
                                                  value="#{customer.country.name}"/>
                                </p:column>

                                <h:outputText value="Company:"/>
                                <h:outputText value="#{customer.company}"/>

                                <h:outputText value="Representative:"/>
                                <p:column>
                                    <p:graphicImage name="images/avatar/#{customer.representative.image}"
                                                    library="demo"
                                                    width="32" style="vertical-align: middle"/>
                                    <h:outputText style="vertical-align: middle; margin-left: .5rem"
                                                  value="#{customer.representative.name}"/>
                                </p:column>

                            </h:panelGrid>

                        </p:outputPanel>

                        <p:commandLink update=":form:customerDetail" oncomplete="PF('customerDialog').show()"
                                       title="View Detail">
                            <h:outputText styleClass="ui-icon pi pi-search" style="margin:0 auto;"/>
                            <f:setPropertyActionListener value="#{customer}" target="#{dtLazyView.selectedCustomer}"/>
                        </p:commandLink>

                        <p:divider />

                    </h:panelGrid>
                </p:dataList>

                <p:dialog header="Customer Info" widgetVar="customerDialog" modal="true" showEffect="blind"
                          hideEffect="explode" resizable="false">
                    <p:outputPanel id="customerDetail" style="text-align:center;">
                        <p:panelGrid columns="2" cellpadding="5" rendered="#{not empty dtLazyView.selectedCustomer}">

                            <h:outputText value="Name:"/>
                            <h:outputText value="#{dtLazyView.selectedCustomer.name}"/>

                            <h:outputText value="Country"/>
                            <p:column>
                                <span class="flag flag-#{dtLazyView.selectedCustomer.country.code}"
                                      style="width: 30px; height: 20px"/>
                                <h:outputText style="vertical-align: middle; margin-left: .5rem"
                                              value="#{dtLazyView.selectedCustomer.country.name}"/>
                            </p:column>

                            <h:outputText value="Company:"/>
                            <h:outputText value="#{dtLazyView.selectedCustomer.company}"/>

                            <h:outputText value="Representative:"/>
                            <p:column>
                                <p:graphicImage name="images/avatar/#{dtLazyView.selectedCustomer.representative.image}"
                                                library="demo"
                                                width="32" style="vertical-align: middle"/>
                                <h:outputText style="vertical-align: middle; margin-left: .5rem"
                                              value="#{dtLazyView.selectedCustomer.representative.name}"/>
                            </p:column>

                        </p:panelGrid>
                    </p:outputPanel>
                </p:dialog>
            </h:form>
        </div>
    </ui:define>

</ui:composition>
